import React from 'react'
import { NavBar, Icon } from 'antd-mobile'
import './index.scss'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router-dom'

// 要求: 必须传入一个字符串的标题!!! this.props.children校验
class NavHeader extends React.Component {
  static propTypes = {
    children: PropTypes.string.isRequired,
  }
  render() {
    return (
      <div className="navHeader">
        <NavBar
          mode="dark"
          icon={<Icon type="left" />}
          onLeftClick={() => this.props.history.go(-1)}
          rightContent={this.props.rightContent}
        >
          {this.props.children}
        </NavBar>
      </div>
    )
  }
}

// 自己封装的直接使用的组件, 没有路由相关的参数的, 需要用到react-router官方的高阶组件: withRouter
// const CatWithMouse = withMouse(Cat)
// Cat本身没有跟随鼠标变化的x y的, 通过高阶组件增强后, 通过props传值, 就能拿到跟随鼠标变化的x y了

// 默认自己直接封装的组件, 需要withRouter包装后, 才能得到 this.props.history match location信息
// const NavHeaderWithRouter = withRouter(NavHeader)
// export default NavHeaderWithRouter

export default withRouter(NavHeader)
